package com.xyrl.project.app.controller.sales;

import com.xyrl.common.base.exception.XyrlException;
import com.xyrl.project.app.util.ShiroUtil;
import com.xyrl.project.common.base.vo.ResponseData;
import com.xyrl.project.common.constant.XyrlConstant;
import com.xyrl.project.common.log.enu.SmsSendType;
import com.xyrl.project.common.log.service.SmsSendLogService;
import com.xyrl.project.common.store.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className SalesSendController
 * @company 星纭融链科技服务有限公司
 * @author 徐恩源
 * @version 1.0
 * @date 2019-12-30 15:18:18
 * @Description 短信发送
 *  
 */
@RestController
@RequestMapping("/sales/send")
@Api(value = "发送验证码", tags = "发送验证码")
public class SalesSendController {
    @Autowired
    private StoreService storeService;
    @Autowired
    private SmsSendLogService smsSendLogService;


    /**
     * 发送短信验证码
     *
     * @param mobile
     * @author 徐恩源
     * @date 2019-12-30 16:42:29
     */
    @ApiOperation("发送注册验证码")
    @PostMapping("/registerCode/{mobile}")
    public ResponseData registerCode(@PathVariable("mobile") String mobile) {
        Long salesmanId = ShiroUtil.loginUserId();
        // 检查手机号
        storeService.checkMobile(mobile, salesmanId);
        String templateId = XyrlConstant.SMS_REGISTER_TEMPLATE_ID;
        try {
            smsSendLogService.sendSmsVerificationCode(mobile, templateId, SmsSendType.registerCode.getValue(), salesmanId);
        } catch (XyrlException e) {
            return ResponseData.error(e.getMessage());
        }
        return ResponseData.success();
    }

}
